<template>
  <DataList
   :cate="cate"
   :cols="cols" 
    ref="datalist"
    :excelHeader="excelHeader"
    skipExcelNumber="2"
     :name="name"/>
</template>
<script>
import DataList from "@/components/DataList";
import { getUser } from "@/utils/auth";
import { get教师基本情况ByGH,get教师基本情况 } from "@/api/教师基本情况";
import linq from "linq"
import { addXsgljbqk, deleteXsgljbqk, updateXsgljbqk, getXsgljbqk, bulkAddXsgljbqk } from "@/api/专职学生管理人员情况.js";
import {findComponent} from "@/utils/ui";
export default {
  components: {
    DataList
  },
  data() {
    return {
      cate: "A8-3专职学生管理人员基本情况表",
       name:'8.3 专职学生管理人员情况',
       excelHeader:{B3:"教工号",C3:"姓名",D3:"是否在编",E3:"来源",F3:"岗位职能",G3:"本岗位工作年限（年）",H3:"从事学生管理年限（年）",I3:"是否专职政治辅导员",J3:"是否专职心理咨询师"},
      cols: [
        { label: "教师所属系部", prop: "BMMC" },
        { label: "教工号", prop: "GH" },
        { label: "姓名", prop: "XM" },
        { label: "是否在编", prop: "XZ_SFZB" },
        { label: "性别", prop: "XZ_XB" },
        { label: "出生日期", prop: "CSRQ" },
        { label: "民族", prop: "XZ_MZ" },
        { label: "学历", prop: "XZ_XL" },
        { label: "学位", prop: "XZ_XW" },
        {
          label: "专业技术职务(最高)",
          data: [
            { label: "等级", prop: "XZ_ZYJSZW_DJ" },
            { label: "名称", prop: "ZYJSZW_MC" },
            { label: "发证单位", prop: "ZYJSZW_FZDW" },
            { label: "获取日期(年月)", prop: "ZYJSZW_HQRQ" }
          ]},
       
        { label: "来源", prop: "XZ_LY" },
        { label: "岗位职能", prop: "GWZN" },
        { label: "本岗位工作年限(年)", prop: "BGWGZNX" },
        { label: "从事学生管理年限(年)", prop: "CSXSGLGZNX" },
        { label: "是否专职政治辅导员", prop: "XZ_SFZZFDY" },
        { label: "是否专职心理咨询师", prop: "XZ_SFZZZXS" },
      ]
    };
  },
  methods: {
    getSummaries(list){
      //
        const sums = [];
         this.cols.forEach((column, index) => {
            sums[index]="";
        });
        sums[6]= "系部数:"+linq.from(list).distinct("$.BMMC").count();
        sums[7]= "人数:"+linq.from(list).distinct("$.GH").count();
        sums[9]= "在编："+linq.from(list).where("$.XZ_SFZB=='是'").count();
        sums[10]= "女："+linq.from(list).where("$.XZ_XB=='女'").count();
        sums[12]= "少数名族："+linq.from(list).where("$.XZ_MZ !='汉族'").count();
        sums[13]= "大学或以上："+linq.from(list).where("$.XZ_XL !='专科'&& $.XZ_XL !='专科以下'").count();
        sums[14]= "学位："+linq.from(list).where("$.XZ_XW =='学士' || $.XZ_XW=='硕士' || $.XZ_XW=='博士'").count();
        sums[15]= "中级或以上:"+linq.from(list).where("$.XZ_ZYJSZW_DJ =='高级' || $.XZ_ZYJSZW_DJ=='中级'").count();
        sums[17]= "具有专业技术职务："+linq.from(list).count("$.ZYJSZW_FZDW");
        sums[21]= "平均:"+linq.from(list).average("$.BGWGZNX").toFixed(2);
        sums[22]= "平均:"+linq.from(list).average("$.CSXSGLGZNX").toFixed(2);
        sums[23]= "专职政治辅导员："+linq.from(list).where("$.XZ_SFZZFDY=='是'").count();
        sums[24]= "专职心理咨询师："+linq.from(list).where("$.XZ_SFZZZXS=='是'").count();
        return sums;
        },
     onDlgCreated(model) {
       
    
      
    },
    onDlgCreated(model) {
       
     
      //
     
      //
    },
    async  bulkAdd(array){
       await  bulkAddXsgljbqk({Xsgljbqk:array});
    },
    //别的页面不用复制此方法
    
    // onChange(model, field, value) {
    //   //
      
    //   if (field == "BMMC") {
    //     var zydm =  linq.from(this.$root.教师基本情况).where(item=>item.BMMC==value).distinct("$.ZYDM").toArray();
    //     var dd = findComponent(this,"ZYMC");
    //     dd.$attrs.items =zydm.map(item => {
    //       return { value: item.ZYMC, label: item.ZYMC,zydm:item.ZYDM };
    //     });
        
    //     model.ZYMC = dd.$attrs.items[0].value;
    //     model.ZYDM = dd.$attrs.items[0].zydm;
    //     //dd.$children[0].setCurrentValue(dd.$attrs.items[0].ZYDM);
    //   }
    //   if(field == "ZYMC"){
        
    //     var zydm =  linq.from(this.$root.教师基本情况).where(item=>item.ZYMC==value).toArray();
    //     //var dd = findComponent(this,"ZYDM");
    //     model.ZYDM = zydm[0].ZYDM;
    //   }
    //   //
    ///导入检查方法
     check(array,list) {
     return new Promise(async (resolve,reject)=>{
         try{
          var user = getUser();
          var 教工号 = await get教师基本情况(user.XXID,user.CJPC)
         
    
         
          //是否已经存在相同
          
          var err =  linq.from(array).select("$.GH + '' ").except(linq.from(教工号).select("$.GH + '' ").toArray()).toArray();
          linq.from(array).where(e=>err.indexOf(e.GH) !==-1).forEach(e=>e.error=e.error?e.error+";":''+"教师基本情况表不存在对应的教工号");
          //把错误的教师姓名替代掉
          err =  linq.from(array).select("$.GH").intersect(linq.from(教工号).select("$.GH").toArray()).toArray();
          linq.from(array).where(e=>err.indexOf(e.GH) !==-1).
          forEach(e=>{
            var d = linq.from(教工号).firstOrDefault(item=>item.GH == e.GH);
            if(d){
              e.XM = d.XM;
              e.BMMC = d.BMMC;
              e.XZ_XB = d.XZ_XB;
              e.CSRQ = d.CSRQ;
              e.XZ_MZ = d.XZ_MZ;
              e.XZ_XL = d.XZ_XL;
              e.XZ_XW = d.XZ_XW;
              e.XZ_ZYJSZW_DJ = d.XZ_ZYJSZW_DJ;
              e.ZYJSZW_MC = d.ZYJSZW_MC;
              e.ZYJSZW_FZDW = d.ZYJSZW_FZDW;
              e.ZYJSZW_HQRQ = d.ZYJSZW_HQRQ;
              
            }
          });
            resolve();
          }catch(e){
            reject(e);
          }
     }) 
    },
     async  onChange(model, field, value) {
      
       if(field == "GH"){
         if(value == "error"){
           console.log("error")
          model.BMMC=""
          model.GH="";
          model.XM= "";
          model.XZ_XB="";
          model.CSRQ="";
          model.XZ_MZ="";
          model.XZ_XL="";
          model.XZ_XW="";
          model.XZ_ZYJSZW_DJ="";
          model.ZYJSZW_MC = "";
          model.ZYJSZW_FZDW ="";
          model.ZYJSZW_HQRQ="";
          
         }else{
         var d1 =  await get教师基本情况ByGH(this.$root.user.XXID,this.$root.user.CJPC,value);
        
           console.log("udpate ")
          model.BMMC=d1[0].BMMC;
          model.XM= d1[0].XM;
          model.XZ_XB=d1[0].XZ_XB;
          model.CSRQ=d1[0].CSRQ;
          model.XZ_MZ=d1[0].XZ_MZ;
          model.XZ_XL=d1[0].XZ_XL;
          model.XZ_XW=d1[0].XZ_XW;
          model.XZ_ZYJSZW_DJ=d1[0].XZ_ZYJSZW_DJ;
          model.ZYJSZW_MC = d1[0].ZYJSZW_MC;
          model.ZYJSZW_FZDW = d1[0].ZYJSZW_FZDW;
          model.ZYJSZW_HQRQ = d1[0].ZYJSZW_HQRQ;
          
         }
       }
      //
    },

    async fetchData() {
      var user = getUser();
      var datas = await getXsgljbqk(user.XXID,user.CJPC);
      return datas;
    },
       add_check(model,list){
      //
          //是否已经存在数据
          var first =  linq.from(list).firstOrDefault(e=>e.GH ==  model.GH);
         
          if(first)
          return "已经存在对应教工号"
      //
    },
     onadd(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           try{
       
          console.log(JSON.stringify(temp));
          var model = await addXsgljbqk(temp);
          resolve(model);
           }catch(e){
             reject(e);
           }
      })
      
    },
    onupdate(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
          console.log(JSON.stringify(temp));
          var model = await updateXsgljbqk(temp);
          resolve(model);
      })
      //
    },
    ondelete(model) {
       var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
        
         await deleteXsgljbqk(temp);
          resolve();
      })
    }
  }
};
</script>
<style>
</style>